package com.wind.cloud.demo.controller;

import com.wind.cloud.demo.feign.HelloFeignService;
import com.wind.cloud.demo.vo.ParamVo;
import com.wind.cloud.demo.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@Slf4j
@RestController
public class ConsumerController {

    @Autowired
    private HelloFeignService helloFeignService;

    @RequestMapping(value = "/hello/feign", method = RequestMethod.GET)
    public String helloFeign() {
        return helloFeignService.hello("test");
    }

    @RequestMapping(value = "/hello/feignPost", method = RequestMethod.GET)
    public ResultVo helloFeignPost() {
        ParamVo param = new ParamVo();
        param.setParam("test");
        return helloFeignService.hello(param);
    }

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping(value = "/hello/ribbon", method = RequestMethod.GET)
    public String helloRibbon() {
        return restTemplate.getForEntity("http://WIND-DEMO-PROVIDER/hello", String.class).getBody();
    }

}
